﻿using MovieTheaterApp.DataModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity.Migrations;

namespace MovieTheaterApp.Db
{
    public static class Seeder
    {
        public static void Seed(
            ApplicationDbContext db, 
            bool seedMovies = true, 
            bool seedReviews = true,
            bool seedActors = true,
            bool seedActorMovies = true
            )
        {
           
                if (seedMovies)
                {
                    //seed movies
                     db.Movies.AddOrUpdate(
                  p => p.Title,
                  new Movie { Title = "Guardians of the Galaxy", Poster = "http://media.aintitcool.com/media/uploads/2014/nordling/guardians.jpg", Rating = Rating.PG_13},
                  new Movie { Title = "Dark Knight", Poster = "http://ia.media-imdb.com/images/M/MV5BMTMxNTMwODM0NF5BMl5BanBnXkFtZTcwODAyMTk2Mw@@._V1_SX640_SY720_.jpg", Rating = Rating.PG_13 },
                  new Movie { Title = "X-Men days of future past", Poster = "http://slotsmarvel.com/wp-content/uploads/2014/06/x-men-days-of-future-past-professor-x.jpg", Rating = Rating.PG_13 },
                  new Movie {Title = "Limitless", Poster="http://www.impawards.com/2011/posters/limitless_ver4_xlg.jpg", Rating=Rating.PG_13}
                );
                     db.SaveChanges();

                }
                if (seedReviews)
                {
                    db.Reviews.AddOrUpdate(
                 p => p.Title,
                 new Review { Title = "Meets my expectations", Comment = "Soo..exciting!", MovieId=1 },
                 new Review { Title ="Good", Comment="It was good...left me hanging.", MovieId=2},
                 new Review {Title="Love It!", Comment="This movie rocks!", MovieId=3}
               );
                    db.SaveChanges();
                }
                if (seedActors)
                {
                    db.Actors.AddOrUpdate(
                        p => p.Name,
                        new Actor { Name = "Christian Bale" },
                        new Actor { Name = "Bradley Cooper" },
                        new Actor { Name = "Vin Diesel" }
                        );
                    db.SaveChanges();
                }
                if (seedActorMovies)
                {
                    db.ActorMovies.AddOrUpdate(
                        p => new { p.ActorId, p.MovieId },
                        new ActorMovie { ActorId = 1, MovieId = 2 },
                        new ActorMovie { ActorId = 2, MovieId = 1 },
                        new ActorMovie { ActorId = 2, MovieId = 4 },
                        new ActorMovie { ActorId = 3, MovieId = 1 }
                        );
                    db.SaveChanges();
                }
            
        }
    }
}
